package boxync;

import java.io.File;
import java.util.ArrayList;
import java.util.Date;

public class BoxyncFile extends FileInfo {
    public BoxyncFile(BoxyncDir _parent, String _path) {
        file = _path;
        initFileInfo(_parent);
    }
    
    public BoxyncFile(String fileInfo) {
        name = BoxyncFile.getFileName(fileInfo);
        deleted = BoxyncFile.isDeleted(fileInfo) ? (byte)1 : (byte)0;
        timeStamp = new Date(BoxyncFile.getYear(fileInfo), BoxyncFile.getMonth(fileInfo), 
                BoxyncFile.getDate(fileInfo), BoxyncFile.getHour(fileInfo), 
                BoxyncFile.getMinute(fileInfo), BoxyncFile.getSecond(file));
    }
    
    @Override
    public void delete() {
        deleted = 1;
        new File(file).delete();
    }
    
    public final void initFileInfo(BoxyncDir _parent) {
        File f = new File(file);
        name = f.getName();
        timeStamp = new Date(f.lastModified());
        timeStamp.setYear(timeStamp.getYear() + 1900);
        
        if (_parent.name.equals(""))
            parent = "";
        else
            parent = _parent.parent + "/" + _parent.name;
        
        deleted = 0;
    }
    
    /**
     * String BoxyncFile yg akan dikirim ke Client / Server
     * @return 
     */
    @Override
    public String toString() {
        return parent + "/" + name + "#" + timeStampString() + "#" + deleted;
    }
    
    public String fullString() {
        StringBuilder sb = new StringBuilder();
        
        sb.append(name).append("\t").append(file.length()).append(" B")
                .append("\t").append(timeStampString()).append("\t").append(deleted)
                .append("\n");
        
        return sb.toString();
    }
    
    public static void main(String[] args) {
        
    }
}
